package com.baidu.sggc.entity;

import lombok.Getter;

/**
 * 操作类型枚举（匹配审计组件的操作代码规则）
 * * 说明：
 * - 系统事件 (category = "SYS") 使用 SYS_* 编码（例如 SYS_LOGIN）
 * - 业务事件 (category = "BIZ") 使用 BIZ_* 编码；其中 CRUD/查询遵循审计组件的约定：
 *   新增/修改/删除/查询 => BIZ_DATA_ADD / BIZ_DATA_MODIFY / BIZ_DATA_DELETE / BIZ_DATA_SELECT
 */
@Getter
public enum OperateType {
    // --- System events (必须为 SYS) ---
    ILLEGAL_ACCESS("SYS", "NoPermission", "越权访问", "SYS_ILLEGAL_ACCESS"),
    LOGIN("SYS", "login", "用户登录", "SYS_LOGIN"),
    LOGOUT("SYS", "logout", "用户退出", "SYS_LOGOUT"),

    // --- Business events (BIZ) ---
    CREATE("BIZ", "create", "新建", "BIZ_DATA_ADD"),
    DELETE("BIZ", "delete", "删除", "BIZ_DATA_DELETE"),
    UPDATE("BIZ", "update", "修改", "BIZ_DATA_MODIFY"),
    CANCEL("BIZ", "cancel", "取消", "BIZ_CANCEL"),
    SCHEDULE("BIZ", "schedule", "调度", "BIZ_SCHEDULE"),
    EXECUTE("BIZ", "execute", "执行", "BIZ_EXECUTE"),
    PUBLISH("BIZ", "publish", "发布", "BIZ_PUBLISH"),
    REGISTER("BIZ", "register", "注册", "BIZ_REGISTER"),
    BIND("BIZ", "bind", "绑定", "BIZ_BIND"),
    UNBIND("BIZ", "unbind", "解绑", "BIZ_UNBIND"),
    DISABLE("BIZ", "disable", "停用", "BIZ_DISABLE"),
    ENABLE("BIZ", "enable", "启用", "BIZ_ENABLE"),
    IMPORT("BIZ", "import", "导入", "BIZ_IMPORT"),
    EXPORT("BIZ", "export", "导出", "BIZ_EXPORT"),
    UPLOAD("BIZ", "upload", "上传", "BIZ_UPLOAD"),
    DOWNLOAD("BIZ", "download", "下载", "BIZ_DOWNLOAD"),
    COPY("BIZ", "copy", "复制", "BIZ_COPY"),
    TERMINATE("BIZ", "terminate", "释放", "BIZ_TERMINATE"),
    RESTART("BIZ", "restart", "重启", "BIZ_RESTART"),
    START("BIZ", "start", "启动", "BIZ_START"),
    STOP("BIZ", "stop", "停止", "BIZ_STOP"),
    AUTHORIZE("BIZ", "authorize", "授权", "BIZ_AUTHORIZE"),
    REBUILD("BIZ", "rebuild", "重建", "BIZ_REBUILD"),
    EXCEEDS_AUTHORIZED("BIZ", "exceedsAuthorized", "越权尝试", "BIZ_EXCEEDS_AUTHORIZED"),
    SHARE("BIZ", "share", "共享", "BIZ_SHARE"),
    CLAIM("BIZ", "claim", "认领", "BIZ_CLAIM"),
    RETURN("BIZ", "return", "退回", "BIZ_RETURN"),
    TRAIN("BIZ", "train", "训练", "BIZ_TRAIN"),
    END("BIZ", "end", "终止", "BIZ_END"),
    CONSTRUCT("BIZ", "construct", "构建", "BIZ_CONSTRUCT"),
    ONLINE("BIZ", "online", "上线", "BIZ_ONLINE"),
    LIST_QUERY("BIZ", "listQuery", "列表查询", "BIZ_DATA_SELECT"),
    DETAILS_QUERY("BIZ", "detailsQuery", "详情查询", "BIZ_DATA_SELECT"),
    RETRAIN("BIZ", "retrain", "重训", "BIZ_RETRAIN");

    private final String category;  // "SYS" 或 "BIZ"
    private final String enName;    // 英文名称（可能用于与外部传入字段匹配）
    private final String zhName;    // 中文名称
    private final String code;      // 最终写入到审计系统的操作编码

    OperateType(String category, String enName, String zhName, String code) {
        this.category = category;
        this.enName = enName;
        this.zhName = zhName;
        this.code = code;
    }

    public static OperateType getByCode(String code) {
        if (code == null) {
            return null;
        }
        for (OperateType value : values()) {
            if (value.code.equalsIgnoreCase(code)) {
                return value;
            }
        }
        return null;
    }

    public static OperateType getByEnName(String enName) {
        if (enName == null) {
            return null;
        }
        for (OperateType value : values()) {
            if (value.enName.equalsIgnoreCase(enName)) {
                return value;
            }
        }
        return null;
    }

    public static OperateType getByZhName(String zhName) {
        if (zhName == null) {
            return null;
        }
        for (OperateType value : values()) {
            if (value.zhName.equals(zhName)) { // 中文一般精确匹配
                return value;
            }
        }
        return null;
    }
}